package com.o2opuzi.lib.web;

import java.io.IOException;
import java.util.Date;
import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.core.MethodParameter;
import org.springframework.ui.ModelMap;


public interface WebHelper{

	/**
	 * @param name
	 * @param value
	 * @return
	 */
	WebHelper attribute(String name,Object value);
	
	/**
	 * @param attrs
	 * @return
	 */
	WebHelper attributeAll(Map<String, Object> attrs);
	
	/**
	 * @param view
	 * @return
	 */
	WebHelper view(String view);
	
	/**
	 * @param view
	 * @return
	 */
	WebHelper render(String view);
	
	/**
	 * @param location
	 */
	void sendRedirect(String location);
	
	/**
	 * @param location
	 * @return
	 */
	String redirect(String location);
	
	/**
	 * @param modelMap
	 * @return
	 */
	WebHelper redirectModel(ModelMap modelMap);
	
	/**
	 * @param path
	 * @return
	 */
	String realPath(String path);
	
	/**
	 * @return
	 */
	String getIpAddress();
	
	/**
	 * @return
	 */
	String getRequestOS(); 
	
	String getClientType();
	
	/**
	 * @return
	 */
	String path();
	
	/**
	 * @return
	 */
	String contextPath();
	
	/**
	 * @param name
	 * @return
	 */
	String getParam(String name);
	
	/**
	 * @param name
	 * @return
	 */
	String[] params(String name);
	
	/**
	 * @param name
	 * @return
	 */
	<T> T sessionAttr(String name);
	
	/**
	 * @param name
	 * @param value
	 * @return
	 */
	WebHelper sessionAttr(String name,Object value);
	
	WebHelper removeSessionAttr(String name);
	
	/**
	 * @return
	 */
	HttpServletRequest getRequest();
	
	/**
	 * @return
	 */
	HttpServletResponse getResponse();
	
	/**
	 * @return
	 */
	ServletContext getServletContext();
	
	/**
	 * @return
	 */
	HttpSession getSession();
	
	/**
	 * @return
	 */
	String getSessionId();
	
	/**
	 * @param name
	 * @param value
	 */
	void addCookie(String name,String value);
	
	/**
	 * @param name
	 * @param value
	 * @param expiry
	 */
	void addCookie(String name,String value,int expiry);
	
	/**
	 * @param cookie
	 */
	void addCookie(Cookie cookie);
	
	/**
	 * @param name
	 * @return
	 */
	Cookie getCookie(String name);
	
	/**
	 * @param name
	 * @return
	 */
	String getCookieValue(String name);
	
	/**
	 * 删除cookie
	 * @param name
	 */
	void removeCookie(String name);
	
	/**
	 * @param name
	 * @param data
	 * @return
	 */
	String jsonp(String name,Object data);
	
	/**
	 * @param data
	 * @return
	 */
	String jsonp(Object data);
	
	/**
	 * @return
	 */
	MethodParameter getParameter();
	
	/**
	 * @param url
	 * @return
	 */
	String encodeUrl(String url);
	
	/**
	 * @param url
	 * @return
	 */
	String decodeUrl(String url);
	
	/**
	 * @return
	 */
	String host();
	
	/**
	 * @return
	 */
	String hostAndPort();
	
	/**
	 * 
	 * @return
	 */
	String locationHost();
	
	/*
	 */
	String getParamToString(String name);
	
	/**
	 * 
	 * @param name
	 * @return
	 */
	Integer getParamToInteger(String name);
	
	/**
	 * 
	 * @param name
	 * @param defaultValue
	 * @return
	 */
	Integer getParamToInteger(String name,Integer defaultValue);
	
	
	/**
	 * 
	 * @param name
	 * @return
	 */
	Long getParamToLong(String name);
	
	/**
	 * 
	 * @param name
	 * @param defaultValue
	 * @return
	 */
	Long getParamToLong(String name,Long defaultValue);
	
	/**
	 * @param name
	 * @return
	 */
	Date getParamToDate(String name);
	
	
	Double getParamToDouble(String name);
	
	MapParam getParamMap();
	
	void forward(Map<String, Object> data,String view) throws ServletException, IOException;
	
	boolean isGet();
	
	boolean isPost();
	
	boolean isAjaxRequest();
	
	Map<String, Object> getRequestBodyToMap();
	
	String getRequestBody();
	
	
}
